begintownscript;

variables;
// These are variables I *typically* use.  Yours may vary.
short bmessage,pcs,seated,leadchar,rctx,rcty;
string custom_m;

body;

beginstate INIT_STATE;

// Setting the crime level because it's a friendly town.
	set_crime_tolerance(5);

// Is the fort taken over?  If so, change things.  If not, leave things how they are.
	if(get_flag(8,0) == 0){
		enable_add_chars(1);
		set_terrain(28,7,0);
		set_terrain(29,7,0);
		set_terrain(28,9,0);
		set_terrain(27,10,0);
		set_terrain(24,12,0);
		set_terrain(24,13,0);
		set_terrain(27,13,0);
		set_terrain(26,14,0);
		set_terrain(27,14,0);
		set_terrain(28,15,0);
		set_terrain(23,16,0);
		set_terrain(24,16,0);
		set_terrain(26,16,0);
		set_terrain(27,17,0);
		set_terrain(25,18,0);
		set_terrain(24,29,0);
		set_terrain(22,30,0);
		set_terrain(25,30,0);
		set_terrain(22,31,0);
		set_terrain(24,31,0);
		set_terrain(24,32,0);
		set_terrain(25,32,0);
		set_terrain(27,32,0);
		set_terrain(20,33,0);
		set_terrain(21,33,0);
		set_terrain(20,34,0);
		set_terrain(23,34,0);
		set_terrain(21,35,0);
		set_terrain(22,35,0);
		set_terrain(24,35,0);
		set_terrain(24,36,0);
		set_terrain(23,11,66);
		set_terrain(24,11,66);
		set_terrain(25,11,66);
		set_terrain(23,37,68);
		set_terrain(24,37,68);
		set_terrain(25,37,68);
		set_terrain(20,39,0);
		set_terrain(19,40,0);
		set_terrain(19,41,0);
	}
	else{
		turn_off_training(1);
		move_item_on_spot(27,7,-1,-1);
		move_item_on_spot(27,8,-1,-1);
		move_item_on_spot(27,9,-1,-1);
		move_item_on_spot(21,39,-1,-1);
		move_item_on_spot(21,40,-1,-1);
		move_item_on_spot(21,41,-1,-1);
		pcs = 6;
		while(pcs <= 65){
			erase_char(pcs);
			pcs = (pcs + 1);
		}
		if(get_flag(12,0) == 0){
			activate_hidden_group(1);
			force_instant_terrain_redraw();
			reset_dialog();
			add_dialog_str(0,"Goddamnit!  The fort has been taken!",0);
			add_dialog_str(1,"Within the walls of the fort and behind its closed gates, you can hear the sounds of carousing.  The goblins have probably taken all of the alcohol out of the larder, and are consuming it with great gusto.",0);
			add_dialog_str(2,"What's worse is, the Morrow Tribe now possesses shining, new chain mail and pikes and longswords.  Nevermind that they can now defend themselves from within sturdy, wooden walls and iron portcullises!",0);
			add_dialog_str(3,"The warriors protecting the gates are pretty inebriated, but they don't look stupid enough to open the gates under any circumstances.  It looks like the fort is pretty solidly theirs, and you don't stand any chance of taking it back.",0);
			add_dialog_str(4,"This is a disaster.  All you have left to do now is tell Brigadier General Francois about it, and probably get demoted.",0);
			add_dialog_choice(0,"...");
			bmessage = run_dialog(1);
			set_flag(12,0,1);
		}
	}

// Setting creatures' names and dialog pics.
	set_name(6,"Klemens");
	set_char_dialogue_pic(6,1960,0);
	set_name(34,"Alphonse");
	set_char_dialogue_pic(34,1957,0);

// Recording party's size -- this is not a trick you need to know
	if(get_flag(2,0) == 0)
		set_flag(2,0,party_size());

// Setting up the party's bedroom -- this is not a trick you need to know
	if(get_flag(2,0) < 4)
		set_terrain(9,6,0);
	if(get_flag(2,0) < 3)
		set_terrain(8,6,0);
	if(get_flag(2,0) < 2){
		set_terrain(7,6,0);
		set_terrain(11,8,0);
	}
	if(get_flag(2,0) > 1)
		set_terrain(11,6,0);

// Moving the storeroom guards into the party's way.
	if(get_flag(1,0) == 0){
		set_character_facing(11,0);
		set_character_facing(12,0);
		relocate_character(12,32,41);
	}

// Eliminating soldiers in center of fort if they've already went north.
	if(get_flag(1,0) >= 2){
		erase_char(51);
		erase_char(52);
		erase_char(53);
		erase_char(54);
		erase_char(55);
		erase_char(56);
		erase_char(57);
		erase_char(58);
	}

break;

beginstate EXIT_STATE;

// Setting flag that states that party has left fort.
	if(get_flag(1,0) == 1)
		set_flag(1,0,2);

break;

beginstate START_STATE;

// Punishing the party for breaking the law (with death).
	if(get_crime_level() > 0){
		message_dialog("Even though you are technically in command of this fortress, treason is still illegal.","Given that you lie between hostile territory and Empire territory, it is inevitable that you either die in the wilderness or are arrested and court martialed.  Game over.");
		kill_char(1000,3,0);
	}

break;

beginstate 10;

	if(get_flag(1,0) == 0){
		message_dialog("Klemens, apparently, still has new orders for you.  Now is not the time to be leaving the fort.","");
		block_entry(1);
	}

break;

beginstate 11;

	message_dialog("This region does not grow its own food.  Thus, the larder is of immense importance, which is why nobody is allowed inside.  Not even you, with the rank of Captain.","");
	block_entry(1);

break;

beginstate 12;

	message_dialog("The soldiers here are decently outfitted, but not with anything special.  Of course, the soldiers here are also staring directly at their possessions, and would probably disapprove of your taking them.","You shut the cabinet.");

break;

beginstate 13;

	message_dialog("The storehouse here has shining, gleaming, new weapons, just ready to be taken by new soldiers sent to the fort.  Of course, they are for new soldiers, not you.","Even though you hold the rank of Captain, the guard here is under strict orders not to let anyone taking anything out of the cabinets.  Not even you.");

break;

beginstate 14;

	message_dialog("However poor the soldiers are here, the workers are poorer still.  Even if you wanted to take their few, meager posessions, well...","...okay, you probably could.  But why would you want to?");

break;

